﻿using System.Text;
using System.Web.Mvc;

namespace ShopB2C.Helper
{
    public static class HtmlMetaHelper
    {
        private const string _copyRight = "Power by ShopB2C";

        /// <summary>
        /// 输出html标题
        /// </summary>
        /// <param name="html">HtmlHelper</param>
        /// <param name="title">title</param>
        /// <returns>html title</returns>
        public static string HtmlTitle(this HtmlHelper html , string title)
        {
            return HtmlTitle(html , title , null);
        }
        /// <summary>
        /// 输出html description
        /// </summary>
        /// <param name="html">HtmlHelper</param>
        /// <param name="description">Description</param>
        /// <returns>html description</returns>
        public static string HtmlTitle(this HtmlHelper html , string title , string keywords)
        {
            return HtmlTitle(html , title , keywords , null);
        }
        /// <summary>
        /// 输出HtmlkeyWords
        /// </summary>
        /// <param name="html">HtmlHelper</param>
        /// <param name="keywords">KeyWords</param>
        /// <returns>html keywords</returns>
        public static string HtmlTitle(this HtmlHelper html , string title , string keywords , string description)
        {

            StringBuilder sb = new StringBuilder();

            if (!string.IsNullOrEmpty(title))
                sb.Append(string.Format("<title>{0} - {1}</title>" , title , _copyRight));

            if (!string.IsNullOrEmpty(keywords))
                sb.Append(string.Format("<meta name=\"keywords\" content=\"{0},{1}\"/>" , keywords , _copyRight));


            if (!string.IsNullOrEmpty(description))
                sb.Append(string.Format("<meta name=\"description\" content=\"{0},{1}\"/>" , description , _copyRight));

            return sb.ToString();

        }
    }
}
